<script>
    $(function() {
        var set=1;
        var unset=0;
        jQuery( function() {
            $( '.checkall' ).live('click', function() {
                $( '.chbx-element' ).each(function () {
                    if(set==1){ $( '.chbx-element' ).attr('checked', true); unset=0; }
                    if(set==0){ $( '.chbx-element' ).attr('checked', false); unset=1; }
                });
                set=unset;
            });
            $( '.deleteall' ).live('click', function() {
                $( '.chbx-element' ).each(function () {
                    $( '.chbx-element' ).attr('checked', true);
                });
            });
        });
    });
</script>
<div class="box">
    <h4 class="white">Users list</h4>
    <div class="box-container">
        <form action="" method="post" id="del-user">
            <table class="table-long">
                <thead>
                    <tr>
                        <td></td>
                        <td>User</td>
                        <td>Fullname</td>
                        <td>Position</td>
                        <td>Actions</td>
                    </tr>
                </thead>
                <tfoot>
                    <tr>
                        <td class="col-chk"><input class="checkall" type="checkbox" /></td>
                        <td colspan="4"><div class="align-right">
                                <select name="deleteoption" class="form-select">
                                    <option value="optional">Bulk Options</option>
                                    <option value="deleteall" class="deleteall">Delete All</option>
                                </select>
                                <a href="#" class="button del-user"><span>perform action</span></a></div>
                        </td>
                    </tr>
                </tfoot>
                <tbody>
                    <?php
                    if (isset($this->users)) {
                        foreach ($this->users as $i => $user) {
                            ?>
                            <tr <?php echo (($i + 1) % 2) ? "class='odd'" : "" ?>>
                                <td class="col-chk"><input name ="users[]" value ="<?php echo $user->id ?>"  class="chbx-element" type="checkbox" /></td>
                                <td class="col-second row-nav"><a href="/user/profile/<?php echo $user->id ?> "><?php echo $user->username ?></a> </td>
                                <td class="col-second"><?php echo $user->fullname ?></td>
                                <td class="col-second"><?php echo $user->position ?></td>
                                <td class="row-nav">
                                    <a href="/user/edit/<?php echo $user->id ?>" class="table-edit-link">Edit</a> <span class="hidden"> | </span> <a href="/user/delete/<?php echo $user->id ?>" id="delete-user"class="table-delete-link">Delete</a>
                                </td>
                            </tr>
                            <?php
                        }
                    }
                    ?>
                </tbody>
            </table>  
        </form>
    </div><!-- end of div.box-container -->
</div> <!-- end of div.box -->